﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
using FamilyBook.Core.Entities;
using FamilyBook.Core.Services;

namespace FamilyBook.UI.WPF.ViewModels
{
    public class TransactionsListViewModel : BaseListViewModel<TransactionDetailsViewModel>
    {
        private readonly IList<Account> _accounts;
        private readonly IList<Product> _products;

        public TransactionsListViewModel(IEnumerable<Transaction> transactions, AccountService<Account> acctSrv, GeneralService<Product, int> prodSrv)
        {
            _accounts = acctSrv.GetAccounts().ToList();
            _products = prodSrv.GetItemsList().ToList();
            ListModel = new ListCollectionView(transactions.Select(x => new TransactionDetailsViewModel(x, _products, _accounts)).ToList());
        }

        protected override TransactionDetailsViewModel CreateDetailsViewModel()
        {
            var trn = new Transaction();
            return new TransactionDetailsViewModel(trn, _products, _accounts);
        }
    }
}
